
'''
    ddt:
        data  driver  test:
    1. ddt修饰类
    2. data引入数据
    3. unpack解包
'''


from unittest import TestCase
from ddt import ddt  # 修饰类
from ddt import data  # 引入数据源
from ddt import unpack # 解包
from Calc import Calc
import xlrd
from xlutils import copy
# 任务1：做文件参数化
yz=[]
da = xlrd.open_workbook(filename="calc.xls",encoding_override=True)
biao=da.sheet_by_index(0)
rows = biao.nrows
col = biao.ncols
for i in range(1,rows):
    hang=biao.row_values(i)[:-3]
    yz.append(hang)
print(yz)
@ddt
class TestCalc(TestCase):

    @data(*yz[0:])
    @unpack  # 解包
    def testAdd1(self,d,a,b,c):
        calc = Calc()
        s = calc.add(a,b)
        self.assertEqual(s,c)
        wb=xlrd.open_workbook(filename="calc.xls",encoding_override=True)
        wb=copy.copy(wb)
        sheet_w=wb.get_sheet(0)
        sheet_w.write(d,4,"通过")
        wb.save("calc.xls")





        # # 任务2：测试结果回写到excel表格里
        #
        # if c != s:
        #     xlwt.write(1,3,"失败！")
        # else:
        #     xlwt.write(1,3,"成功！")
        #
        # self.assertEqual(s,c)



















